package com.bachongLightNovel.message.socket;

import com.bachongLightNovel.utils.UserInfoUtil;
import jakarta.websocket.OnClose;
import jakarta.websocket.OnMessage;
import jakarta.websocket.OnOpen;
import jakarta.websocket.Session;
import jakarta.websocket.server.PathParam;
import jakarta.websocket.server.ServerEndpoint;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.pqc.crypto.newhope.NHOtherInfoGenerator;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * webSocket服务
 * @author vermouth
 */

@Component
@ServerEndpoint(value = "/ws/socket/{userId}")
@Slf4j
public class WebSocketServer {

    public static final Map<Long, Session> sessionPools=new ConcurrentHashMap<>();

    @OnMessage
    public void onMessage(Session session,String message){
        log.info("接收到客户端消息");
    }

    @OnOpen
    public void onOpen(Session session, @PathParam(value = "userId") Long userId){
        log.info("客户端建立连接:{}",userId);
        sessionPools.put(userId,session);
    }

    @OnClose
    public void onClose(Session session,@PathParam(value = "userId") Long userId){
        log.info("客户端关闭连接:{}",userId);
        sessionPools.remove(userId);
    }
}
